#include "playlist.h"

class PlaylistEntry
{
public:
    PlaylistEntry(int _duration, QString _title, QUrl _url) :
            duration(_duration), title(_title), url(_url)
    {   }

    int duration;
    QString title;
    QUrl url;
};

Playlist::Playlist()
{
}

void Playlist::addTrack(QUrl url, QString title, int duration)
{
    entries.append(new PlaylistEntry(duration, title, url));
}

QString Playlist::toString()
{
    QString playlist("#EXTM3U\n");
    for(int i=0; i<entries.count(); i++)
    {
        playlist += "#EXTINF:" + QString::number(entries[i]->duration)
                    + "," + entries[i]->title + "\n";
        playlist += entries[i]->url.toString() + "\n";
    }

    return playlist;
}

Playlist::~Playlist()
{
    for(int i=0; i<entries.count(); i++)
        delete entries[i];
}
